package com.jh.wdbc.service;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.jh.wdbc.model.ConnectionInfo;

public class ConnectionFactory {
	public static Connection createConnection(String dbType, String url, String user, String passwd) throws ClassNotFoundException, SQLException{
		Class.forName(dbType);
		return DriverManager.getConnection(url, user, passwd);
	}
	
	public static void setConnection(ConnectionInfo connectionInfo){
		try {
			connectionInfo.setConnection(createConnection(connectionInfo.getDbType(), connectionInfo.getUrl(), connectionInfo.getUser(), connectionInfo.getPasswd()));
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
